Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

Fixes #40041

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner December 6, 2019 20:04
@CyrusNajmabadi
Copy link
Member Author

Tagging @sharwell

@CyrusNajmabadi
Copy link
Member Author

Note: i'd recommend reviewing this a commit at a time.

Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i preserved this logic (just in O(1) time instead of O(n)). But, overall, i think preserving this logic is pretty unnecessary. i don't see why we actually need it.

spans[spans.Count - 1] = TextSpan.FromBounds(lastSpan.Start, mod.Span.End);
return true;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i preserved this logic (just in O(1) time instead of O(n)). But, overall, i think preserving this logic is pretty unnecessary. i don't see why we actually need it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It highlights the entire async code section rather than the highlighting the nested inside keywords Async and Await.
Personally i prefer the latter.

return;
case LocalDeclarationStatementSyntax localDeclaration:
if (localDeclaration.AwaitKeyword.Kind() == SyntaxKind.AwaitKeyword && localDeclaration.UsingKeyword.Kind() == SyntaxKind.UsingKeyword)
if (localDeclaration.UsingKeyword.Kind() == SyntaxKind.UsingKeyword)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i preserved this logic. But i dont' actually think it's necessary. this basically ensures that we only highlight await in await using var whatever and not in await var whatever. However, the latter is broken code, so it would be fine IMO to highlight there.

AnonymousFunctionExpressionSyntax anonymousFunction => TryAddAsyncOrAwaitKeyword(anonymousFunction.AsyncKeyword, spans),
UsingStatementSyntax usingStatement => TryAddAsyncOrAwaitKeyword(usingStatement.AwaitKeyword, spans),
LocalDeclarationStatementSyntax localDeclaration =>
localDeclaration.UsingKeyword.Kind() == SyntaxKind.UsingKeyword && TryAddAsyncOrAwaitKeyword(localDeclaration.AwaitKeyword, spans),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i preserved this logic. But i dont' actually think it's necessary. this basically ensures that we only highlight await in await using var whatever and not in await var whatever. However, the latter is broken code, so it would be fine IMO to highlight there.

@jinujoseph jinujoseph added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Dec 6, 2019
@AdamSpeight2008
Copy link
Contributor

The would also need applying to the vb side as well.

@CyrusNajmabadi
Copy link
Member Author

@AdamSpeight2008 my goal is not to harden the entirely of the IDE codebase to stack overflows.

@CyrusNajmabadi
Copy link
Member Author

@sharwell LMK what you need here to proceed.

@CyrusNajmabadi
Copy link
Member Author

@sharwell @jinujoseph LMK what you need here to proceed.

@sharwell
Copy link
Contributor

sharwell commented Dec 13, 2019

@CyrusNajmabadi What is the observable impact of e55e787? There are disadvantages to both the before and after code and understanding the impact will help with the decision:

  • Before code: disadvantage of changing the behavior of the algorithm. A few more nodes will be visited than before.
  • After code: disadvantage of pushing the either tree of nodes into a stack, which is likely to frequently be very large (possibly prohibitively so)

@CyrusNajmabadi
Copy link
Member Author

CyrusNajmabadi commented Dec 13, 2019

@CyrusNajmabadi What is the observable impact of e55e787? There are disadvantages to both the before and after code and understanding the impact will help with the decision:

It was actually incorrect. i.e. it didn't highlight things properly. this was because it dove into nodes it shoudln't (i.e. an async lambda inside an async lambda).

After code: disadvantage of pushing the either tree of nodes into a stack, which is likely to frequently be very large (possibly prohibitively so)

Note: thsi was the same in both cases. calling DescendantNodesAndSelf works internally using an explicit (pooled) stack. You always pay this cost.

@sharwell
Copy link
Contributor

Note: thsi was the same in both cases. calling DescendantNodesAndSelf works internally using an explicit (pooled) stack. You always pay this cost.

The part I missed was the use of yield return between pushing things to the stack. I was looking at it as pushing all nodes in the tree to the stack before starting to visit the children. Thanks for the clarification.

@CyrusNajmabadi
Copy link
Member Author

Thanks for the clarification.

Absolutely!

@CyrusNajmabadi
Copy link
Member Author

@sharwell good to merge this in?

@CyrusNajmabadi
Copy link
Member Author

@sharwell everything has passed. merge when you can, thanks!

@sharwell sharwell merged commit 0c056f0 into dotnet:master Dec 13, 2019
@CyrusNajmabadi CyrusNajmabadi deleted the asyncAwaitIterative branch December 13, 2019 22:49
@sharwell sharwell added this to the 16.5.P2 milestone Dec 13, 2019
@CyrusNajmabadi
Copy link
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VS crash. C# code analysis out of stack due to recursion in AsyncAwaitHighlighter.HighlightRelatedKeywords

5 participants